﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO;

namespace FDeal.PH_Admin
{
    public partial class ChiTietThanhVien : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                for (int i = DateTime.Now.Year - 30; i <= DateTime.Now.Year;i++)
                {
                    dlNamSinh.Items.Add(i.ToString());
                }
                if (Request.QueryString["id"] == null)
                {
                    Response.Redirect("~/PH_Admin/ThanhVien.aspx");
                }
                else
                {
                    LoadDuLieu();
                }
            }
        }
        public static THONGTINTAIKHOAN thongTinTaiKhoan;
        public static String sIDTaiKhoang;
        public void LoadDuLieu()
        {
            sIDTaiKhoang = Request.QueryString["id"].ToString();
            ThongTinTaiKhoanBUS thongTinTaiKhoanBUS = new ThongTinTaiKhoanBUS();
            thongTinTaiKhoan = thongTinTaiKhoanBUS.ChiTiet(sIDTaiKhoang);
 
            dlGuocGia.Text = thongTinTaiKhoan.QUOCGIA;;
            dlTinhThanh.Text = thongTinTaiKhoan.TINHTHANH;;

            dlNgaySinh.Text = thongTinTaiKhoan.NGAYSINH.Value.Day.ToString();;
            dlThangSinh.Text = thongTinTaiKhoan.NGAYSINH.Value.Month.ToString();;
            dlNamSinh.Text = thongTinTaiKhoan.NGAYSINH.Value.Year.ToString();;

            String gioitinh = thongTinTaiKhoan.GIOITINH;
            if (gioitinh == "Nam")
            {
                rdbtGioiTinhNam.Checked = true;
                rdbtGioiTinhNu.Checked = false;
            }
            else
            {
                rdbtGioiTinhNam.Checked = false;
                rdbtGioiTinhNu.Checked = true;
            }

            tbTenThanhVien.Text = thongTinTaiKhoan.TENDANGNHAP;
            tbEmailThanhVien.Text = thongTinTaiKhoan.EMAIL;

            tbTVMatKhau.Text = thongTinTaiKhoan.MATKHAU;
            tbTVNhapLaiMatKhau.Text = thongTinTaiKhoan.MATKHAU;

            int loaiTaiKhoanh = int.Parse(thongTinTaiKhoan.LOAITAIKHOAN.ToString());
            if (loaiTaiKhoanh == 2)
            {
                rdbtAdmin.Checked = true;
                rdbtTKDoanhNghiep.Checked = false;
                rdbtTKThuong.Checked = false;
            }
            if (loaiTaiKhoanh == 1)
            {
                rdbtAdmin.Checked = false;
                rdbtTKDoanhNghiep.Checked = true;
                rdbtTKThuong.Checked = false;
            }
            else
            {
                rdbtAdmin.Checked = false;
                rdbtTKDoanhNghiep.Checked = false;
                rdbtTKThuong.Checked = true;
            }
         }
        protected void btThayDoiDoanhNghiep_Click(object sender, EventArgs e)
        {
            ThongTinTaiKhoanBUS thongTinTaiKhoanBUS = new ThongTinTaiKhoanBUS();
            thongTinTaiKhoan.TENDANGNHAP = tbTenThanhVien.Text;
            thongTinTaiKhoan.EMAIL = tbEmailThanhVien.Text;
            if(rdbtGioiTinhNam.Checked == true)
                thongTinTaiKhoan.GIOITINH = "Nam";
            else
                thongTinTaiKhoan.GIOITINH = "Nữ";
            DateTime dt = new DateTime(int.Parse(dlNamSinh.Text.ToString()),int.Parse(dlThangSinh.Text.ToString()),int.Parse(dlNgaySinh.Text.ToString()));
            thongTinTaiKhoan.NGAYSINH = dt;
            thongTinTaiKhoanBUS.Sua(thongTinTaiKhoan);
            Response.Redirect("~/PH_Admin/ThanhVien.aspx");
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alertMe();", true);
        }

        protected void btCanelDoanhNghiep_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/PH_Admin/ThanhVien.aspx");
        }

        protected void btXoaTV_Click(object sender, EventArgs e)
        {
            ThongTinTaiKhoanBUS thongTinTaiKhoanBUS = new ThongTinTaiKhoanBUS();
            thongTinTaiKhoan = thongTinTaiKhoanBUS.ChiTiet(sIDTaiKhoang);
            thongTinTaiKhoanBUS.Xoa(thongTinTaiKhoan);
        }
    }
}